package com.ruoyi.product.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.product.domain.SupplierProduct;
import com.ruoyi.product.service.ISupplierProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 药品供货情况Controller
 * 
 * @author ruoyi
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/product/product")
public class SupplierProductController extends BaseController {
    @Autowired
    private ISupplierProductService supplierProductService;

    /**
     * 查询药品供货情况列表
     */
    @PreAuthorize("@ss.hasPermi('product:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierProduct supplierProduct) {
        startPage();
        List<SupplierProduct> list = supplierProductService.selectSupplierProductList(supplierProduct);
        return getDataTable(list);
    }

    /**
     * 导出药品供货情况列表
     */
    @PreAuthorize("@ss.hasPermi('product:product:export')")
    @Log(title = "药品供货情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierProduct supplierProduct) {
        List<SupplierProduct> list = supplierProductService.selectSupplierProductList(supplierProduct);
        ExcelUtil<SupplierProduct> util = new ExcelUtil<SupplierProduct>(SupplierProduct.class);
        util.exportExcel(response, list, "药品供货情况数据");
    }

    /**
     * 获取药品供货情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(supplierProductService.selectSupplierProductById(id));
    }

    /**
     * 新增药品供货情况
     */
    @PreAuthorize("@ss.hasPermi('product:product:add')")
    @Log(title = "药品供货情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierProduct supplierProduct) {
        return toAjax(supplierProductService.insertSupplierProduct(supplierProduct));
    }

    /**
     * 修改药品供货情况
     */
    @PreAuthorize("@ss.hasPermi('product:product:edit')")
    @Log(title = "药品供货情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierProduct supplierProduct) {
        return toAjax(supplierProductService.updateSupplierProduct(supplierProduct));
    }

    /**
     * 删除药品供货情况
     */
    @PreAuthorize("@ss.hasPermi('product:product:remove')")
    @Log(title = "药品供货情况", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(supplierProductService.deleteSupplierProductByIds(ids));
    }
}
